<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
  import { mapActions } from 'vuex';

  export default {
    watch: {
      $userInfo() {
        if (this.$userInfo.info) {
          this.$service
            .AssetUserTeachers({
              size: 10000,
            })
            .then((res) => {
              this.$getTeacherList(res.rows);
            });

          // 获取分类
          this.$service.CategoryAll().then((res) => {
            this.$getCateTree(this.removeEmptyArray(res, 'childs'));
          });
        }
      },
    },
    methods: {
      ...mapActions(['$getTeacherList', '$getCateTree']),
      removeEmptyArray(arr, key, level = 1) {
        return arr.map((a) => {
          if (Array.isArray(a[key])) {
            if (a[key].length === 0) {
              delete a[key];
            } else {
              a[key] = this.removeEmptyArray(a[key], 'childs', level + 1);
            }
          }
          a.level = level;
          return a;
        });
      },
    },
  };
</script>

<style>
  #app {
    width: 100%;
    min-height: 100vh;
    background: #eee;
  }
</style>
